/**
 *    Copyright (c) [2022] [中和农信]
 *    rabbit-mq-plus is licensed under Mulan PSL v2.
 *    You can use this software according to the terms and conditions of the Mulan PSL v2.
 *    You may obtain a copy of Mulan PSL v2 at:
 *             http://license.coscl.org.cn/MulanPSL2
 *    THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *    See the Mulan PSL v2 for more details.
 *
 */
package com.cfpamf.athean.rabbit.mq.plus.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cfpamf.athean.rabbit.mq.plus.domain.builder.RabbitMqPlusEventTaskBuilder;
import com.cfpamf.athean.rabbit.mq.plus.domain.dto.RabbitMqPlusEventTaskDTO;
import com.cfpamf.athean.rabbit.mq.plus.domain.po.RabbitMqPlusEventTaskPO;
import com.cfpamf.athean.rabbit.mq.plus.repository.RabbitMqPlusEventTaskRepository;
import com.cfpamf.athean.rabbit.mq.plus.service.RabbitMqPlusEventTaskService;
import com.cfpamf.athena.utils.ObjectUtils;

/**
 * 类RabbitMqPlusEventTaskServiceImpl.java的实现描述：
 *
 * @author Andy（陈洪桥）2022年11月26 15:36
 */
@Service
public class RabbitMqPlusEventTaskServiceImpl implements RabbitMqPlusEventTaskService {

    @Resource
    private RabbitMqPlusEventTaskRepository rabbitMqPlusEventTaskRepository;

    @Override
    @Transactional
    public void save(RabbitMqPlusEventTaskDTO dto) {
        RabbitMqPlusEventTaskPO eventTaskPO = RabbitMqPlusEventTaskBuilder.buildRabbitMqPlusEventTaskPO(dto);
        rabbitMqPlusEventTaskRepository.save(eventTaskPO);
    }
    
    @Override
    public int countByEventNoAndEventCode(String eventNo, String eventTypeCode) {
        return rabbitMqPlusEventTaskRepository.countByEventNoAndEventCode(eventNo, eventTypeCode);
    }
    
    
    @Override
    public RabbitMqPlusEventTaskDTO queryByEventNoAndEventCode(String eventNo, String eventTypeCode) {
        RabbitMqPlusEventTaskPO eventTaskPO =
            rabbitMqPlusEventTaskRepository.selectOneByEventNoAndEventCode(eventNo, eventTypeCode);
        return ObjectUtils.copyPropertys(eventTaskPO, RabbitMqPlusEventTaskDTO.class);
    }

    @Override
    public List<RabbitMqPlusEventTaskDTO> queryTodoDataByStatus(List<Integer> status) {
        List<RabbitMqPlusEventTaskPO> data = rabbitMqPlusEventTaskRepository.queryTodoDataByStatus(status);
        return ObjectUtils.copyListProperties(data, RabbitMqPlusEventTaskDTO.class);
    }

    @Override
    @Transactional
    public boolean updateByEventNoAndEventCode(RabbitMqPlusEventTaskDTO dto) {
        RabbitMqPlusEventTaskPO eventTaskPO = ObjectUtils.copyPropertys(dto, RabbitMqPlusEventTaskPO.class);
        eventTaskPO.setUpdateTime(eventTaskPO.getCreateTime());
        return rabbitMqPlusEventTaskRepository.updateByEventNoAndEventCode(eventTaskPO);
    }

    @Override
    public boolean deleteInvalidDataByDay(int day) {
        return rabbitMqPlusEventTaskRepository.deleteInvalidDataByDay(day);
    }

}
